package com.xjtu.chapter09;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/2 21:58
 */
public class IteratorTest {
    public static void main(String[] args) {
        ArrayList<String> cartoons = new ArrayList<String>();
        cartoons.add("grey wolf");
        cartoons.add("little red riding hood");
        //创建一个cartoons集合对应的迭代器
        Iterator<String> it = cartoons.iterator();
        while (it.hasNext()){
            String mm = (String)it.next();
            System.out.println("remove: "+mm);
            if (mm.equals("grey wolf")) it.remove();
            System.out.println("cartoon is: "+it.next());
        }
    }
}
